﻿//----------------------------------------------------------------------->
function fn_message(type, message) {
    var result = '';
    switch (type) {
        case "s":
            result = '<div class="myForm1_alert"><span class="icon_acceptcheckconfirmedgogreenokpositiveyes"></span><p class="style_alert">' + ((message == undefined) ? "Saved successfully!" : message) + '</p></div>'
            break;
        case "e":
            result = '<div class="myForm1_alert"><span class="icon_alert_blockcanceldeleteapprove"></span><p class="style_alert">' + ((message == undefined) ? "An error occurred while saving" : message) + '</p></div>';
            break;
        case "i":
            result = '<div class="myForm1_alert"><span class="icon__alert_information"></span><p class="style_alert">' + ((message == undefined) ? "Warning!" : message) + '</p></div>';
            break;
        default:
            result = '<div class="myForm1_alert"><span class="icon__alert_information"></span><p class="style_alert">Warning!</p></div>';
            break;
    }
    $('div[id$=message_row]').stop(false,true).empty().fadeIn().append(result).delay("6000").fadeOut();
}
function fn_removeValidation() {
    $(".formError").each(function (index) {
                        $(this).stop();
                        $(this).remove();
    });
    
}
function fn_trim(strTexto) {
    return strTexto.replace(/^\s+/g,'').replace(/\s+$/g,'');
}
function fn_callmethod(url, data, success, error) {
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: success,
        error: error
    });
}

function validatenumber(e) {
    if (e.keyCode == 32) {
        return false;
    } else
        if (e.keyCode > 105 || e.keyCode < 96) {
            if (isNaN(String.fromCharCode(e.keyCode)) && e.keyCode != 8 && e.keyCode != 37 && e.keyCode != 39 && e.keyCode != 46) {
                return false;
            }
        }
    return e;
}

function Replace(String, replace) {

    return String.replace(/^\s+|\s+$/g, replace);

}

function fn_jsonreplace(data) {

    var temp = "";
    for (var i = 0; i < data.length; i++) {
        if (data[i] == '"')
            temp = temp + "'";
        else
            temp = temp + data[i];

    }
    return temp;
}
//JqGridDinamyc---------------------------------------------------------->
function fn_BuildColNameArray(obj) {
    var array = new Array();
    var i = 0;
    for (property in obj[0]) {
        array[i] = property;
        i++;
    }
    return array;
}

function fn_BuildColModelArray(obj) {
    var array = new Array();
    var i = 0;
    for (property in obj[0]) {
        array[i] = { name: property, index: property, width: 100, align: 'center' };
        i++;
    }
    return array;
}

function fn_GenerateTable(tbname, captionString, object, w, gp , ms) {
    try {
        jQuery("#" + tbname).jqGrid({
            datatype: "local",
            height: 'auto',
            width: w,
            colNames: fn_BuildColNameArray(object),
            colModel: fn_BuildColModelArray(object),
            pager:gp,
            viewrecords: true,
            sortorder: 'desc',
            rowNum: 20,
            rowList: [20, 40, 60],
            multiselect: ms,
            caption: captionString
        });
    }
    catch (e) { }
}
function fn_GenerateFillTable(tableID,obj) {
    try {
        var len = obj.length;
        for (var i = 0; i < len; i++) {
            var arrayRow = {};
            for (property in obj[i]) {
                arrayRow[property] = obj[i][property];
            }
            jQuery("#" + tableID).jqGrid('addRowData', i + 1, arrayRow);
        }
    }
    catch (e) { }
}

//----------------------------------------------------------------------->
 function Open_Window(the_url) {
              var description = "top=0, left=0, toolbar=no,location=no, status=no,menubar=no,scrollbars=no, resizable=no, width=900,height=500";
              var title = "Titulo";
              window.open(the_url, title, description);
 }
 function fn_loadshow(id) {
     $("#loader-box").css("left", $("#" + id).offset().left);
     $("#loader-box").css("top", $("#" + id).offset().top);
     $("#loader-box").height($("#" + id).height());
     $("#loader-box").width($("#" + id).width());
     $("#loader-box").removeClass("hide");
 }

 function fn_loadhide() {
     $("#loader-box").addClass("hide");
 }
 function fn_getURLParameter(name) {
     return unescape((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]);
 }

 function fn_JsonReplace(data) {

     var temp = "";
     for (var i = 0; i < data.length; i++) {
         if (data[i] == '"')
             temp = temp + "'";
         else
             temp = temp + data[i];

     }
     return temp;
 }